#include "editor.h"
#include <QMouseEvent>

Editor::Editor(QWidget* parent)
    : QsciScintilla(parent)
{

}

Editor::~Editor()
{
}

int Editor::getCurrentLine() const
{
    int line, index;
    getCursorPosition(&line, &index);
    qDebug() << "光标位置:" << line << index;
    return line;
}

void Editor::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        getCurrentLine();
        qDebug() << getCurrentLineText();
        return;
    }
    QWidget::mousePressEvent(event);
}

QString Editor::getCurrentLineText() const
{
    return text(getCurrentLine());
}

void Editor::setupIndentation()
{
    setIndentationsUseTabs(false);
    setIndentationWidth(4);
    setTabWidth(4);
    setAutoIndent(true);
    setIndentationGuides(true);
    setIndentationGuidesBackgroundColor(QColor("#FF0000"));
    setIndentationGuidesForegroundColor(QColor("#0000FF"));
}

void Editor::setupMargins()
{
    // 行号边距
    setMarginType(0, QsciScintilla::NumberMargin);
    setMarginWidth(0, "0000");
    setMarginLineNumbers(0, true);
    setMarginsBackgroundColor(QColor("#f0f0f0"));
    setMarginsForegroundColor(QColor("#666666"));

    // 折叠边距
    setMarginType(1, QsciScintilla::SymbolMargin);
    setMarginWidth(1, 20);
    setMarginSensitivity(1, true);
}

void Editor::setupColors()
{
    // 设置选择颜色
    setSelectionBackgroundColor(QColor("#316AC5"));
    setSelectionForegroundColor(QColor("#ffffff"));

    // 设置当前行颜色
    setCaretLineBackgroundColor(QColor("#ffffcc"));

    // 设置匹配括号颜色
    setMatchedBraceBackgroundColor(QColor("#ffff00"));
    setUnmatchedBraceBackgroundColor(QColor("#ff0000"));
}













